package com.linchuansi.base;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * *
 *
 * @author wb
 * @date 2025-11-08 18:31*@since 1.0.0
 */
public class CallableTest implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("callable");
        Thread.sleep(1000);
        return "callable";
    }
    static class Task2 implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("runnable");
        }
    }
    static class Task3 implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("runnable");
        }
    }
    public static void main(String[] args) throws Exception {
        Long startTime=System.currentTimeMillis();
        ExecutorService executor = Executors.newFixedThreadPool(4);
        executor.submit(new Task2());
        executor.submit(new Task3());
        Future<String> future = executor.submit(new CallableTest());
        String s = future.get();
        System.out.println(s);
        Long endTime=System.currentTimeMillis();
        Long time=endTime-startTime;
        System.out.println("执行完毕总共耗时="+time);
    }
}
